package MeteoCal.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @authors Guttadoro, Iommazzo, Saullo
 */
@Entity
@Table(name = "notification")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Notification.findAll", query = "SELECT n FROM Notification n"),
    @NamedQuery(name = "Notification.findByIdNotification", query = "SELECT n FROM Notification n WHERE n.idNotification = :idNotification"),
    @NamedQuery(name = "Notification.findByClosedToEvent", query = "SELECT n FROM Notification n WHERE n.closedToEvent = :closedToEvent"),
    @NamedQuery(name = "Notification.findByDate", query = "SELECT n FROM Notification n WHERE n.date = :date"),
    @NamedQuery(name = "Notification.findByText", query = "SELECT n FROM Notification n WHERE n.text = :text")})
public class Notification implements Serializable {
    private static final long serialVersionUID = 1L;
        
    //Text
    public static final String PERIODICALLY_UPDATE = "periodically update";
    public static final String ONE_DAY_BEFORE= "one day before";
    public static final String THREE_DAYS_BEFORE = "three days before";
    public static final String E_PARTICIPANT = "delete participant";
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @Column(name = "idNotification")
    private Integer idNotification;
    @Basic(optional = false)
    //@NotNull
    @Column(name = "closedToEvent")
    @Temporal(TemporalType.DATE)
    private Date closedToEvent;
    @Basic(optional = false)
    //@NotNull
    @Column(name = "Date")
    @Temporal(TemporalType.DATE)
    private Date date;
    @Basic(optional = false)
    //@NotNull
    @Size(min = 1, max = 300)
    @Column(name = "Text")
    private String text;
    @JoinColumn(name = "idEvent", referencedColumnName = "idEvent")
    @ManyToOne(optional = false)
    private Event idEvent;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "notification")
    private Collection<Receivednotification> receivednotificationCollection;

    public Notification() {
    }

    public Notification(Integer idNotification) {
        this.idNotification = idNotification;
    }

    public Notification(Integer idNotification, Date closedToEvent, Date date, String text) {
        this.idNotification = idNotification;
        this.closedToEvent = closedToEvent;
        this.date = date;
        this.text = text;
    }

    public Integer getIdNotification() {
        return idNotification;
    }

    public void setIdNotification(Integer idNotification) {
        this.idNotification = idNotification;
    }

    public Date getClosedToEvent() {
        return closedToEvent;
    }

    public void setClosedToEvent(Date closedToEvent) {
        this.closedToEvent = closedToEvent;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Event getIdEvent() {
        return idEvent;
    }

    public void setIdEvent(Event idEvent) {
        this.idEvent = idEvent;
    }

    @XmlTransient
    public Collection<Receivednotification> getReceivednotificationCollection() {
        return receivednotificationCollection;
    }

    public void setReceivednotificationCollection(Collection<Receivednotification> receivednotificationCollection) {
        this.receivednotificationCollection = receivednotificationCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idNotification != null ? idNotification.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Notification)) {
            return false;
        }
        Notification other = (Notification) object;
        if ((this.idNotification == null && other.idNotification != null) || (this.idNotification != null && !this.idNotification.equals(other.idNotification))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MeteoCal.entity.Notification[ idNotification=" + idNotification + " ]";
    }
    
}
